package com.tunnel.client.net;

import com.tunnel.common.protocol.Protocol;
import com.tunnel.common.protocol.ProtocolType;
import com.tunnel.common.util.SequenceUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

public class LocalForwardHandler extends SimpleChannelInboundHandler<ByteBuf> {
    // 回调返回的通道
 /*   private Channel callBackChannel;

    public LocalForwardHandler(Channel callBackChannel) {
        this.callBackChannel = callBackChannel;
    }*/

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
        // 通过回调的通道，把本地的接口的数据返回回去
        Protocol protocol = new Protocol();
        String msgtmp = msg.toString(CharsetUtil.UTF_8);
        protocol.setCommonType(ProtocolType.TRANSFER);
        protocol.setSequenceId(SequenceUtil.getSequenceId());
        protocol.setBody(msgtmp);
        protocol.setLength(msgtmp.getBytes().length);
        System.out.println("本地回复消息: " + msgtmp);
        /*callBackChannel.write(protocol);*/

    }
}

